package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.CurriculumSeries;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.CurriculumSeriesQueryObject;
import trlygjj.tanruiliyigenjinjin.service.ICurriculumSeriesService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("curriculumSeries")
public class CurriculumSeriesController {

    @Autowired
    private ICurriculumSeriesService curriculumSeriesService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @RequiresPermissions("curriculumSeries:index")
    @PermissionName("课程系列页面")
    @RequestMapping("")
    public String index(){
        return "curriculumSeries/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @RequiresPermissions("curriculumSeries:list")
    @PermissionName("课程系列数据")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CurriculumSeriesQueryObject qo){
        PageResult result = curriculumSeriesService.query(qo);
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @RequiresPermissions("curriculumSeries:listAll")
    @PermissionName("课程系列全部数据")
    @RequestMapping("listAll")
    @ResponseBody
    public List<CurriculumSeries> listAll(){
        return curriculumSeriesService.selectAll();
    }

    /**
     * 删除
     * @param curriculumSeriesId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumSeries:delete")
    @PermissionName("课程系列删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long curriculumSeriesId){
        JsonResult result = new JsonResult();
        try{
            curriculumSeriesService.deleteByPrimaryKey(curriculumSeriesId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param curriculumSeries 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumSeries:update")
    @PermissionName("课程系列编辑")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(CurriculumSeries curriculumSeries){
        JsonResult result = new JsonResult();
        try{
            curriculumSeriesService.updateByPrimaryKey(curriculumSeries);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param curriculumSeries 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumSeries:save")
    @PermissionName("课程系列保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(CurriculumSeries curriculumSeries){
        JsonResult result = new JsonResult();
        try{
            curriculumSeriesService.insert(curriculumSeries);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
}
